import { PropertyKey } from "@/constants/Enums";
import { DiagramCustomizationManagementModel } from "../../DiagramCustomizationManagementModel";

export class DiagramTableConfigurationModel {
  elementIds: string[] = [];
  columnIds: string[] = [];

  currentProjectId: string;
  isModelDisabled: boolean;

  constructor(public diagramCustomizationManagementModel: DiagramCustomizationManagementModel) {
    this.currentProjectId = diagramCustomizationManagementModel.queryParams.projectId;
    this.isModelDisabled = diagramCustomizationManagementModel.isModelDisabled;
  }

  getData() {
    return {
      [PropertyKey.DiagramTable_rowElementType]: this.elementIds.length ? this.elementIds : undefined,
      [PropertyKey.DiagramTable_columnIds]: this.columnIds.length ? this.columnIds : undefined
    };
  }

  async initData(data) {
    if (data) {
      if (data[PropertyKey.DiagramTable_rowElementType] && data[PropertyKey.DiagramTable_rowElementType].length) {
        this.elementIds = data[PropertyKey.DiagramTable_rowElementType];
      }
      if (data[PropertyKey.DiagramTable_columnIds] && data[PropertyKey.DiagramTable_columnIds].length) {
        this.columnIds = data[PropertyKey.DiagramTable_columnIds];
      }
    }
  }
}
